

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:test01/okhttp_test/pojo/saveBasicFitnessInfo_pojo.dart';
import 'package:test01/okhttp_test/util/request_http.dart';

import 'goals_page.dart';

/*
*
* 登录界面-----输入体型
*
*
* */
class IndexShapePage extends StatefulWidget {
  const IndexShapePage({Key key}) : super(key: key);

  @override
  _IndexShapePageState createState() => _IndexShapePageState();
}

class _IndexShapePageState extends State<IndexShapePage> {

  @override
  Widget build(BuildContext context) {
    return
      Scaffold(
        appBar: AppBar(
          leading: GestureDetector(
            onTap: (){
              Navigator.pop(context);
            },
            child: Icon(
              Icons.arrow_back_ios,
              size: 28,
              color: Colors.black,
            ),
          ),
          backgroundColor: Colors.white,
          elevation: 0,
          automaticallyImplyLeading: true,
        ),
        body:SingleChildScrollView(
          child:  Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(left: 41, top: 42.5),
                child: Text(
                  "你现在的体型？",
                  style:
                  TextStyle(fontSize: 23, color: Color.fromRGBO(17, 17, 17, 1)),
                ),
              ),
              Container(
                margin: EdgeInsets.only(left: 41, top: 12),
                child: Text(
                  "我们将以此为你推荐训练计划，让你一试身手",
                  style:
                  TextStyle(fontSize: 14, color: Color.fromRGBO(51, 51, 51, 1)),
                ),
              ),
              ///轮播图
              SwipPage(),

              SizedBox(height: 32,)

            ],
          ),
        ),

      );
  }
}

///轮播图
class SwipPage extends StatefulWidget {
  const SwipPage({Key key}) : super(key: key);

  @override
  _SwipPageState createState() => _SwipPageState();
}

class _SwipPageState extends State<SwipPage> {
  int swiperIndex;
  int swiperIndex2;

  ///体型选择
  int setupindex;

  SaveBasicFitnessInfo _saveBasicFitnessInfo=SaveBasicFitnessInfo();

  @override
  void initState() {
    // TODO: implement initState
    swiperShape(0);
    super.initState();
  }

  ///计算体型
  void swiperShape(int pictureIndex){
    setupindex=pictureIndex;
    if(pictureIndex<3){
      swiperIndex=(pictureIndex*5)+10;
      swiperIndex2=swiperIndex+4;
    }
    if(pictureIndex==3){
      swiperIndex=(pictureIndex*5)+10;
      swiperIndex2=swiperIndex+5;
    }
    if(pictureIndex==4){
      swiperIndex=(pictureIndex*5)+11;
      swiperIndex2=swiperIndex+9;
    }
    setState(() {
    });
  }


  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Container(
          padding: const EdgeInsets.only(top: 42),
          height: 336,
          child: Swiper(
            scrollDirection: Axis.horizontal,
            duration:3000,
            itemCount: 5,
            // 数量
            autoplay: false,
            // 自动翻页
            itemBuilder: (BuildContext context, int index) {
              // 构建
              return Container(
                height: 284,
                padding: EdgeInsets.only(
                    left: 16.5, right: 16.5, top: 35.5, bottom: 37.5),
                decoration: BoxDecoration(
                  color: Colors.black,
                ),
                child: Image.asset("assets/login_bg.png"),
              );
            },
            //获取当前的下标
            onIndexChanged: (index){
              // setupIndex(index);
              swiperShape(index);
            },
            viewportFraction: 0.39,
            // 当前视窗展示比例 小于1可见上一个和下一个视窗
            scale: 0.8, // 两张图片之间的间隔
          ),
        ),
        Container(
          margin: EdgeInsets.only(top: 12),
          child: Text(
            "${swiperIndex}%-${swiperIndex2}%",
            style:
            TextStyle(fontSize: 16, color: Color.fromRGBO(17, 17, 17, 1)),
          ),
        ),
        GestureDetector(
          onTap: () async{
            print("界面跳转");
            _saveBasicFitnessInfo.bodyType=setupindex;
            bool xx=await saveBasicFitnessInfo(_saveBasicFitnessInfo,"/appuser/web/user/saveBasicFitnessInfo");
            if(xx){
              Navigator.push(context, MaterialPageRoute(builder: (context) {
                return GoalsPage();
              }));
          }},
          child: Container(
            alignment: Alignment.center,
            height: 41,
            decoration: BoxDecoration(
              color: Color.fromRGBO(17, 17, 17, 1),
              borderRadius: BorderRadius.all(Radius.circular(3.0)),
            ),
            width: MediaQuery.of(context).size.width - 82,
            margin: EdgeInsets.only(left: 41, top: 62),
            child: Text(
              "下一步",
              style: TextStyle(
                  fontSize: 16, color: Color.fromRGBO(255, 255, 255, 1)),
            ),
          ),
        ),
      ],
    );
  }
}